<?php
include __DIR__ . "/config/cors.php";
include __DIR__ . "/database.php";

$cookie = @$_COOKIE['role'];
if (!isset($cookie) or $cookie != "admin") {
    echo json_encode([
        "code" => 401,
        "message" => "无权访问！"
    ]);
    exit;
}

$db = new DB();
$sql = "select username, mail, role, register, status, id from user";
$data = $db->selectAll($sql);
if (is_array($data) and count($data) > 0) {
    echo json_encode([
        "code" => 200,
        "message" => "查询成功",
        "data" => $data
    ]);
} else {
    echo json_encode([
        "code" => 202,
        "message" => "暂无用户"
    ]);
}
